/*
 * table_CcObjectMapOfType_t.c
 *
 *  Created on: 2012-5-14
 *      Author: guanxiaoying
 */

#include "../../parser/coredef.h"


#define TableSize  (sizeof(CCOBJECTMAPOFTYPE))
#define TableType  PCCOBJECTMAPOFTYPE
#define stTable stCcObjMapManager.memoryBlocks
#define maxTable stCcObjMapManager.maxRecordNum
#define  maxNumPerBlk  (stCcObjMapManager.astMaxNum_Block)
typedef struct _CCOBJECTMAPOFTYPE
{
	UCHAR  bAdjustable;
	U4  size;
	U4  idx;
	AST astNextObj;
	AST astSameMemObj;
	AST astType;
	AST astSym;
	AST astChild;
	AST astParent;

} CCOBJECTMAPOFTYPE, *PCCOBJECTMAPOFTYPE;

/* get the object */
static TABLEMANAGER stCcObjMapManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stCcObjMapManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stCcObjMapManager, resetListener, index );
	if( temp != NULL ){
		if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
	}
	return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stCcObjMapManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stCcObjMapManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stCcObjMapManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//	ACCESS_BOOL_FIELD bAdjustable;
static BOOL  isAdjustable( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bAdjustable;
}
/* set method */
static BOOL  setAdjustable( AST index, BOOL idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->bAdjustable = idx;
}
//	ACCESS_U4_FIELD   size;
static U4  getSize( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->size;
}
/* set method */
static U4  setSize( AST index, U4 idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->size = idx;
}
//	ACCESS_U4_FIELD   idx;
static U4  getCurrArrayIndex( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->idx;
}
/* set method */
static U4  setCurrArrayIndex( AST index, U4 idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->idx = idx;
}
//	ACCESS_IDX_FIELD  NextObj;
static AST  getNextObj( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNextObj;
}
/* set method */
static AST  setNextObj( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNextObj = idx;
}
//	ACCESS_IDX_FIELD  sameObj; /* for union */
static AST  getSameMemObj( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSameMemObj;
}
/* set method */
static AST  setSameMemObj( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSameMemObj = idx;
}
//	ACCESS_IDX_FIELD  type;
static AST  getType( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType;
}
/* set method */
static AST  setType( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType = idx;
}
//	ACCESS_IDX_FIELD  sym;
static AST  getSym( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSym;
}
/* set method */
static AST  setSym( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astSym = idx;
}
//	ACCESS_IDX_FIELD  child;
static AST  getChild( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astChild;
}
/* set method */
static AST  setChild( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astChild = idx;
}
static AST  getParent( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent;
}
/* set method */
static AST  setParent( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParent = idx;
}
//	ACCESS_IDX_FIELD  parent;


const CCOBJECTMAPOFTYPEACCESS stObjectMapOfTypeAccess = {
		ClearTable,
		ResetTable,
		AllocTable,
		getMaxLineNum,
		{
				isAdjustable,
				setAdjustable
		},
		{
				getSize,
				setSize
		},
		{
				getCurrArrayIndex,
				setCurrArrayIndex
		},
		{
				getNextObj,
				setNextObj
		},
		{
				getSameMemObj,
				setSameMemObj
		},
		{
				getType,
				setType
		},
		{
				getSym,
				setSym
		},
		{
				getChild,
				setChild
		},
		{
				getParent,
				setParent
		}
};
